package cz.muni.fi.pa165.creatures.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * Should be replaced by some enumeration.
 * 
 * This class represents a defense strategy of some {@link CreatureType}.
 *
 * @author xmiklos1
 */
@Entity
@Table(name = "DEFENSE_STRATEGY")
public class DefenseStrategy implements Serializable {

    /**
     * Id of the defense strategy.
     */
    private Long id;
    
    /**
     * Name of the defense strategy.
     */
    private String name;
    
    /**
     * Description of the defense strategy.
     */
    private String description;
    
//    /**
//     * Type of creatures which use this defense strategy.
//     */
//    private List<CreatureType> creatureType = new ArrayList<CreatureType>();

    /**
     * Default constructor
     */
    public DefenseStrategy() {
    }

    /**
     *
     * @param name name of the defense strategy. May not be longer the 255
     * characters.
     */
    public DefenseStrategy(String name) {
        this.name = name;
    }

    /**
     * Gets id of the defense strategy.
     *
     * @return id of the defense strategy
     */
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "ID", nullable = false)
    public Long getId() {
        return id;
    }

    /**
     * Sets id of the defense strategy, may not be null.
     *
     * @param id id of the defense strategy
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Gets name of the defense strategy.
     *
     * @return name of the defense strategy
     */
    @Column(nullable = false, length = 255)
    public String getName() {
        return name;
    }

    /**
     * Sets name of the defense strategy, may not be null and 
     * longer then 255 characters.
     *
     * @param name name of the defense strategy
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Gets description of the defense strategy.
     *
     * @return description of the defense strategy
     */
    @Column(length = 512)
    public String getDescription() {
        return description;
    }

    /**
     * Sets description of the defense strategy, may not be longer then 512
     * characters.
     *
     * @param description description of the defense strategy
     */
    public void setDescription(String description) {
        this.description = description;
    }

//    /**
//     * Gets a list of creature types who use this defense strategy.
//     *
//     * @return list of creature types who use this defense strategy.
//     */
//    @ManyToMany(mappedBy = "defenseStrategies")
//    public List<CreatureType> getCreatureType() {
//        return creatureType;
//    }

//    /**
//     * Sets a list of creature types who use this defense strategy.
//     *
//     * @param creatureType list of creature types who use this defense strategy.
//     */
//    public void setCreatureType(List<CreatureType> creatureType) {
//        this.creatureType = creatureType;
//    }
    
    @Override
    public String toString() {
        return "DefenseStrategy{" + "id=" + id + ", name=" + name
                + ", description=" + description + '}';
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 29 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 29 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DefenseStrategy other = (DefenseStrategy) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }
}
